package org.zhs.linear;

import org.zhs.linear.MyArrayList;

import java.util.Iterator;

/**
 * @Author: Administrator
 * @Date: 2024/3/27 22:27
 * @Version: 1.0
 * @Description:
 */
public class Demo_MyArrayList {

    public static void main(String[] args) {
        MyArrayList<Integer> myArrayList = new MyArrayList<>();

        //这里可以测试我们写的ArrayList的add方法和它的扩容
        for (int i = 0; i < 12; i++) {
            myArrayList.add(i);
        }

        //这里测试，我们实现的Iterator
        Iterator<Integer> iterator = myArrayList.iterator();
        while (iterator.hasNext()){
            Integer next = iterator.next();
            if(next == 10){
                iterator.remove();
            }
            System.out.println(next);
        }

        System.out.println("=========================================");
        //这里测试我们自己实现的foreach方法,并且可以观看迭代器remove之后的结果
        myArrayList.foreach(item -> {
            System.out.println(item);
        });

    }

}
